package com.lc.login.mvp.presenter;

import android.app.Application;

import javax.inject.Inject;

import com.lc.baseres.base.BaseJson;
import com.lc.baseres.base.BasePresenter;
import com.lc.baseres.dagger.scope.ActivityScope;
import com.lc.login.bean.UserSimpleInfo;
import com.lc.login.mvp.contract.LoginContract;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;


@ActivityScope
public class LoginPresenter extends BasePresenter<LoginContract.Model, LoginContract.View> {
    //private RxErrorHandler mErrorHandler;
    private Application mApplication;
    //private ImageLoader mImageLoader;
    //private AppManager mAppManager;

    @Inject
    public LoginPresenter(LoginContract.Model model, LoginContract.View rootView, Application application) {
        super(model, rootView);
        // this.mErrorHandler = handler;
        this.mApplication = application;
        //this.mImageLoader = imageLoader;
        //this.mAppManager = appManager;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        // this.mErrorHandler = null;
        // this.mAppManager = null;
        // this.mImageLoader = null;
        this.mApplication = null;
    }

    public void checkLogin() {
        mModel.checkLogin(mRootView.getUserName(), mRootView.getPassword())
                .subscribe(new Consumer<BaseJson<UserSimpleInfo>>() {
                    @Override
                    public void accept(BaseJson<UserSimpleInfo> userSimpleInfoBaseJson) throws Exception {
                        if (userSimpleInfoBaseJson.getStatus().equals("000000")) {
                            mRootView.showMessage(userSimpleInfoBaseJson.getData().getName() + " login success");
                        } else {
                            mRootView.showMessage("login failure");
                        }
                    }
                });
    }

}
